<template>
  <p @click="handleClick()">{{ message }}</p>
</template>

<script>
export default {
  name: 'MyfirstVue',
  data () {
    return {
      message: '消息!'
    }
  },
  method () {
    this.handleClick()
  },
  methods: {
    handleClick () {
      const that = this
      this.$ajax({
        url: '/hello/hello1',
        method: 'get',
        data: {
          msg: 'Fred'
        },
        transformRequest: [function (data) {
          // Do whatever you want to transform the data
          let ret = ''
          for (let it in data) {
            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
          }
          return ret
        }],
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded',
          'Access-Control-Allow-Origin': '*'
        }
      }).then(function (res) {
        that.message = res.data
      })
    }
  }
}
</script>

<style scoped>

</style>
